//封装一个方法 计算出某某时间是几年 几天几小时之前
 //计算两个时间的时差 相差x天x小时x分x秒
    //所需要的数学知识:减法 除法 取余
    // var time1 = new Date('2021-05-01 18:00:23');

    // var time2 = new Date('2021-04-29 12:10:58');

    function getDiffTime(time1, time2) {

        //1.计算两个时间相差的毫秒数
        var diff = time1 - time2;
        diff = Math.abs(diff);//取绝对值
        // console.log(diff);
        
        //2.根据相差的毫秒数进行换算
        
        var oneDay = 1000 * 60 * 60 * 24; //一天所需要的毫秒数
        
        var oneHours = 1000 * 60 * 60 //一个小时所需要的毫秒数
        
        var oneMinutes = 1000 * 60 //一分钟所需要的毫秒数
        
        var oneSeconds = 1000; //1秒钟所需要的毫秒数
        
        //计算相差多少天,用相差的毫秒数,除以一天的毫秒数;
        var diffDay = diff / oneDay;
        //天数取整
        
        diffDay = parseInt(diffDay)
        
        //计算差多少小时
        
        //把总时差和一天的余数计算出来
        
        var yTime = diff % oneDay;
        
        
        //将剩余的毫秒数转换成小时
        
        var diffHours = yTime / oneHours;
        diffHours = parseInt(diffHours)
        
        //取求完小时之后剩下的余数
        
        var yTime2 = yTime % oneHours
        
        //将取余的毫秒数转换成 分
        
        var diffMinutes = yTime2 / oneMinutes;
        
        
        diffMinutes = parseInt(diffMinutes)

        
        //求分钟之后剩下的余数
        
        var yTime3 = yTime2 % oneMinutes;
        
        
        //求差多少秒
        var diffSeconds = yTime3 / oneSeconds;
        
       
        
        diffSeconds = parseInt(diffSeconds)
        
        var res = diffDay + "天" + diffHours + "小时" + diffMinutes + "分" + diffSeconds + "秒"
        
        
        return res;
        }
        
        var time1 = new Date("1999-12-02 09:15:20");
        
        var time2 = new Date()
        
        console.log(getDiffTime(time1, time2));